package com.xiaor.rssmodel.model;

import com.xiaor.rssmodel.model.common.Common;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.List;

/**
 * 省
 */
@Entity
@Table(name = "province")
@Data   //生成Getter和Setter
@NoArgsConstructor  //生成无参构造函数
@AllArgsConstructor //生成有参构造函数
public class Province extends Common {
    @Column(columnDefinition = "varchar(20) comment '省名'", unique = true)
    private String name;
    @OneToMany
    @JoinTable(name = "province_area",
            joinColumns = {@JoinColumn(name = "pid")},
            inverseJoinColumns = {@JoinColumn(name = "aid")}
    )
    private List<Area> areaList;
    @OneToMany
    @JoinTable(name = "province_redarea",
            joinColumns = {@JoinColumn(name = "pid")},
            inverseJoinColumns = {@JoinColumn(name = "raid")}
    )
    private List<RedArea> redAreaList;

    @Override
    public String toString() {
        return "Province{" +
                "name='" + name + '\'' +
                '}';
    }
}
